package von.seiji.cn.thread;

import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.LinkedList;

/**
 * @Author: SeiJi
 * @DateTime: 2022/2/7 18:03
 * @Description: 此人很懒，未写描述！
 **/
public class T2 implements Runnable{

    //volatile 阻止了while循环内部变量的缓存
    private volatile Integer b = new Integer(0);

    @Override
    public void run() {
        while (true){
            //System.out.println(b);
//            System.out.println(System.identityHashCode(b));
            if(b.equals(2))
                break;
        }

        System.out.println("A is finished!");
    }

    public static void main(String[] args) throws InterruptedException {
        T2 a = new T2();
        Thread thread = new Thread(a);
        thread.start();
        Thread.sleep(1000);
        a.b = 2;
        //阻塞住主线程
//        while (true){}
        thread.join();

    }

    @Test
    public void ldsajf() {
        Integer a = 128;
        Integer b = 128;
        System.out.println(System.identityHashCode(a));
        System.out.println(System.identityHashCode(b));
    }

    @Test
    public void alfkdjafl() {
        LinkedList<Integer> objects = Lists.newLinkedList();
        objects.add(12);
        System.out.println(objects.contains(12));
        objects.add(1222);
        System.out.println(objects.contains(Integer.valueOf(1222)));
    }
}
